package com.cskaoyan.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;

@Component
public class CustomAspect {
    //方法名任意写
    public void before() {
        System.out.println("雪茄好");
    }

    public void after() {
        System.out.println("雪茄再见");
    }

    //类似于InvocationHandler的invoke(proxy,method,args)
    //类似于MethodInterceptor的invoke(methodInvocation)
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        //委托类方法的执行，around方法的执行结果：代理对象的结果
        System.out.println("around的前半部分");
        Object proceed = joinPoint.proceed();
        System.out.println("around的后半部分");

        return proceed;
    }

    //形参来接收委托类方法的返回结果
    public void afterReturning(Object result) {
        System.out.println("afterReturning接收的结果：" + result);
    }

    //形参来接收委托类方法抛出的异常 Exception或Throwable
    public void afterThrowing(Exception exception) {
        System.out.println("afterThrowing:" + exception.getMessage());
    }
}
